package com.atguigu.gulimall.product.web;


import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.Catalog2Vo;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private RedissonClient redissonClient;


    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/index.html","/"})
    public String goToIndex(Model model){
        //获取根分类
        System.out.println(redissonClient);
        List<CategoryEntity> list = categoryService.getLevel1Category();
        model.addAttribute("categorys",list);
        return "index";
    }
    
    
    /**
     * @Author dy
     * @Description:  获取分类json 数据
     */
    @GetMapping("index/catalog.json")
    @ResponseBody
    public Map<String,List<Catalog2Vo>> getCatalogJson(){
        Map<String,List<Catalog2Vo>> map =  categoryService.getCatalogJson();
        return map;
    }





}
